package sql.db;

import java.io.Serializable;
import sql.exception.*;

public class DataType implements Serializable 
{
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private String type = null;
	private int length = 0;
	
	public DataType() {
		super();
		this.type = null;
		this.length = 0;
	}
	
	public DataType(String type) {
		super();
		this.type = type;
	}
	
	public String toString() {
		String str;
		if (type.equals("char")) {
			str = type + "(" + new Integer(length).toString() + ")";
		} else {
			str = type;
		}
		
		return str;
	}
	
	public boolean equals(DataType dtype) {
		if (type.equals(dtype.getType()) && length == dtype.getLength())
			return true;
		else
			return false;
	}
	
	public boolean equalsIgnoreLength(String typeStr) {
		if (type.equals(typeStr))
			return true;
		else 
			return false;
	}

	public String getType() {
		return type;
	}

	public void setType(String type) {
		this.type = type;
	}

	public int getLength() {
		return length;
	}

	public void setLength(int length) throws MyDBException {
		if (length <= 0) 
			throw new CharLengthError();
			
		this.length = length;
	}
}
